package com.lhgray.sglhome.data.repository

import android.net.Uri
import com.freightoa.foundation.net.ApiResult
import com.freightoa.foundation.net.bean.SGLResponse
import com.freightoa.foundation.presentation.repository.BaseRepository
import com.lhgray.sglhome.data.network.api.HomeServer
import com.lhgray.sglhome.domain.model.SourceData
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.android.components.ViewModelComponent
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.MultipartBody
import okhttp3.RequestBody.Companion.toRequestBody
import javax.inject.Inject

@Module
@InstallIn(ViewModelComponent::class)
class PicUploadRepository @Inject constructor() : BaseRepository {
    @Inject
    lateinit var homeServer: HomeServer
    suspend fun uploadPic(list: MutableList<Uri>): Result<String> {

        return when (homeServer.uploadPic(
            description = HashMap(),
            file = MultipartBody.Part.createFormData(
                "file", "", "hello".toRequestBody("image/jpg".toMediaTypeOrNull())
            )
        )) {
            is ApiResult.Success -> {
                Result.success("")
            }

            is ApiResult.Error -> {
                Result.failure(RuntimeException("13"))
            }

            is ApiResult.Exception -> {
                Result.failure(RuntimeException("13"))
            }
        }
    }

    suspend fun getOrderList(fileNo: String): ApiResult<SGLResponse<SourceData>> =
        homeServer.getOrderList("1", fileNo)


}


